﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLQTPM_Nhom6.UTIL;
using System.Data.OleDb;
using QLQTPM_Nhom6.DTO;
using System.Collections;

namespace QLQTPM_Nhom6.DAO
{
    public class DuLieuDAO
    {
        public static ArrayList LayToanBoDuLieu()
        {
            ArrayList arrDuLieu = new ArrayList();
            DataProvider dp = new DataProvider();
            try
            {
                dp.Open();
                string query = "SELECT DULIEU.MaDuLieu, TENDIADIEM.TenDiaDiem, DICHVU.TenDichVu, DULIEU.SoNha, DUONG.TenDuong, PHUONG.TenPhuong, DULIEU.KinhDo, DULIEU.ViDo, DULIEU.ChuThich FROM TINHTHANH INNER JOIN (TENDIADIEM INNER JOIN (QUANHUYEN INNER JOIN (PHUONG INNER JOIN (DUONG INNER JOIN (DICHVU INNER JOIN DULIEU ON DICHVU.MaDichVu = DULIEU.MaDichVu) ON DUONG.MaDuong = DULIEU.MaDuong) ON PHUONG.MaPhuong = DULIEU.MaPhuong) ON QUANHUYEN.MaQuanHuyen = DULIEU.MaQuanHuyen) ON TENDIADIEM.MaTenDiaDiem = DULIEU.MaTenDiaDiem) ON TINHTHANH.MaTinhThanh = DULIEU.MaTinhThanh;";
                dp.Data_Table = dp.ExecuteQuery(query);
                
                for(int i=0;i<dp.Data_Table.Rows.Count;i++)
                {
                    DuLieuDTO dl = new DuLieuDTO();
                    dl.MaDuLieu = int.Parse(dp.Data_Table.Rows[i].ItemArray[0].ToString());
                    dl.TenDiaDiem = dp.Data_Table.Rows[i].ItemArray[1].ToString();
                    dl.TenDichVu = dp.Data_Table.Rows[i].ItemArray[2].ToString();
                    dl.SoNha = dp.Data_Table.Rows[i].ItemArray[3].ToString();
                    dl.TenDuong = dp.Data_Table.Rows[i].ItemArray[4].ToString();
                    dl.TenPhuong = dp.Data_Table.Rows[i].ItemArray[5].ToString();
                    dl.KinhDo = dp.Data_Table.Rows[i].ItemArray[6].ToString();
                    dl.ViDo = dp.Data_Table.Rows[i].ItemArray[7].ToString();
                    dl.ChuThich = dp.Data_Table.Rows[i].ItemArray[8].ToString();
                    arrDuLieu.Add(dl);
                }                
                dp.DisConn();
            }
            catch(Exception ex)
            {
                throw new Exception("Error: " + ex.Message);
            }
            return arrDuLieu;
        }
    }
}
